package com.express.ExpRefundRecord.service;


import com.aqgj.util.DateFarmatUtils;
import com.aqgj.util.JsonWrapper;
import com.express.ExpRefundRecord.bean.ExpRefundRecordVo;
import com.express.ExpRefundRecord.dao.ExpRefundRecordDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;


@Service("ExpRefundRecord")
public class ExpRefundRecordManager {
    @Autowired
    ExpRefundRecordDao expRefundRecordDao;

    //获取退款记录表
    public HashMap<String, Object> getRefundRecordList(Integer pageNo, Integer pageSize) {
        List<ExpRefundRecordVo> list = Collections.EMPTY_LIST;
        List<Object[]> result = expRefundRecordDao.getRefundRecordList(pageNo, pageSize);
        if (result.size() > 0) {
            list = new ArrayList<>();
            for (int i = 0; i < result.size(); i++) {
                ExpRefundRecordVo expRefundRecordVo = new ExpRefundRecordVo();
                expRefundRecordVo.setId(result.get(i)[0].toString());
                expRefundRecordVo.setName(result.get(i)[6].toString());
                expRefundRecordVo.setFkExpOrderId(result.get(i)[1].toString());
                expRefundRecordVo.setOrderMoney(new BigDecimal(result.get(i)[3].toString()));
                expRefundRecordVo.setRefundMoney(new BigDecimal(result.get(i)[4].toString()));
                expRefundRecordVo.setType(Integer.valueOf(result.get(i)[2].toString()));
                expRefundRecordVo.setAddTime(DateFarmatUtils.parse(result.get(i)[5].toString()));
                list.add(expRefundRecordVo);
            }
        }
        return JsonWrapper.successPagerWrapper(list, expRefundRecordDao.getRefundRecordListCount());
    }

}
